package cn.wit.test;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoCount extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		
		//整个web应用里面，只有一个servletContext，在服务器启动得时候会被创建
		ServletContext context = getServletContext();
		
		Integer count = (Integer) context.getAttribute("count");
		
		if(count == null) {
			
			context.setAttribute("count", 1);
			
		}else {
		
			context.setAttribute("count", count+1);
			
		}
		
		System.out.println(count);
		
	}
}
